#include <stdio.h>

int main()
{
	int QZ[] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
	char M[] = {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};

	int N = 0, i = 0, j = 0;
	char input[100][32] = {0};
	int errNum = 0, sum = 0, Z = 0;
	
	//输入N条身份证号
	scanf("%d", &N);
	for(i = 0; i < N; i++){
		scanf("%s", &input[i]);
	}
	printf("\n");

	for(i = 0; i < N; i++){
		sum = 0;
		//前17个一定是数字
		for(j = 0; j < 17; j++){
			if(input[i][j] < '0' || input[i][j] > '9'){
				printf("%s\n", input[i]);
				errNum++;
				goto here;
			}
			sum += QZ[j] * (input[i][j] - '0');	
		}
		//最后一个字符是前17个数字的加权和除以11的余数
		Z = sum % 11;
		if(M[Z] != input[i][j]){
			printf("%s\n", input[i]);
			errNum++;
		}
here:;
	}

	//如果一条都没错，则输出All passed
	if(errNum == 0){
		printf("All passed\n");
	}
	return 0;
}
